<template>
  <div style="width: 100%">
    <span class="toolbar-item"
      ><el-date-picker
        v-model="periods"
        type="monthrange"
        range-separator="至"
        start-placeholder="开始期间"
        end-placeholder="结束期间"
      >
      </el-date-picker
    ></span>
    <span class="toolbar-item">
      <el-button type="primary" @click="handleSearch">刷新</el-button>
    </span>
    <slot name="right"></slot>
  </div>
</template>
<script>
export default {
  data() {
    return {
      periods: [],
    };
  },
  methods: {
    handleSearch() {
      this.$emit("refresh");
    },
  },
  mounted() {
    this.periods = [new Date(), new Date()];
  },
  watch: {
    periods: {
      handler(values) {
        if (values && values.length == 2) {
          this.$emit("changePeriod", values);
        }
      },
    },
  },
};
</script>
<style scoped>
.toolbar-item {
  float: left;
  padding-right: 10px;
}
</style>
